package com.northchurchcolumbus.podcast.ncpodcaster;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import com.apple.eawt.Application;
import com.apple.eawt.ApplicationAdapter;
import com.apple.eawt.ApplicationEvent;

public class NCPodcasterOSXApplication extends ApplicationAdapter
{
    private NCPodcasterGUI podcaster;
    
    public static void main(String[] args) throws Exception
    {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        NCPodcasterGUI frame = new NCPodcasterGUI();
        NCPodcasterOSXApplication app = new NCPodcasterOSXApplication(frame);
        frame.setup();
    }
   
    public NCPodcasterOSXApplication(NCPodcasterGUI gui) throws IOException
    {
        podcaster = gui;
        Application.getApplication().addApplicationListener(this);

        URL artworkFileURL=this.getClass().getResource("/Picture.jpeg");
        InputStream is =artworkFileURL.openStream();
        ImageIcon icon = new ImageIcon(artworkFileURL);
        
        Application.getApplication().setDockIconImage(icon.getImage());
        Application.getApplication().setEnabledPreferencesMenu(true);
    }
    
    public void handleQuit(ApplicationEvent e)
    {
        e.setHandled(true);
        System.exit(0);
    }
    

    public void handleAbout(ApplicationEvent e)
    {
      // tell the system we're handling this, so it won't display
      // the default system "about" dialog after ours is shown.
      e.setHandled(true);
      //TODO: Delegate
      JOptionPane.showMessageDialog(null, "northChurch Podcaster v1.1.0");
    }
    
    public void handlePreferences(ApplicationEvent e)
    {
        e.setHandled(true);
        podcaster.showPreferencesDialog();
    }
    

}
